#ifndef TRIANGULATOR_H
#define TRIANGULATOR_H

class Mesh;
class Tree;

class Base
{
public:
	typedef std::vector< std::pair< cg::Vec3, cg::Vec3 > >	Points;

										Base();	
	Points								points;
	int									Generate( const cg::Vec3 &center, const cg::Vec3 &dir, float radius, unsigned int n, int firstVertex );
	int									firstIndex;
};

class Triangulator
{
public:
												Triangulator( void );
	Mesh*										Triangulate( const Tree& t, float textParamX, float textParamY );
	void										Render();

private:
										
	typedef std::map< int, Base >				Basis; // first value is branchPointIndex
	typedef std::vector<int>					IndicesDyn;	
	Basis										basis;
	IndicesDyn									indicesDyn;
	//
	void										GenerateBasis( const Tree& t );	
	void										GenerateSurface( const Tree& t );
	void										GenerateTextureCoordinates( const Tree& t, float textParamX, float textParamY );
	void										TriangulateBasis( Base firstBase, Base secondBase );
	void										ComputeNormalsFromMesh();
	//
	int											indicesNum;
	int *										indices;
	int											verticesNum;
	int											normalsNum;
	cg::Vec3*									vertices;
	cg::Vec3*									normals;
	cg::Vec2*									tcoords;	
};

CG_INLINE Triangulator::Triangulator( void )
{

}

#endif